home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Power 1997 December
/
MACPOWER-1997-12.ISO.7z
/
MACPOWER-1997-12.ISO
/
AMUG
/
PROGRAMMING
/
Raven 1.2 Examples.sit
/
Raven 1.2 Examples
/
BoxPaint
/
Source
/
Main.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-09-04
|
5KB
|
194 lines
/*
* File: Main.cpp
* Summary: The big enchilada.
* Written by: Jesse Jones
*
* Copyright ゥ 1996 Jesse Jones. All Rights Reserved.
*
* Change History (most recent first):
*
* <-> 2/24/96 JDJ Created.
*/
#include <List.h>
#include <List.h>
#include <Z3DUtils.h>
#include <ZAppBootStrap.h>
#include <ZFloatingDesktop.h>
#include <ZGestalt.h>
#include <ZMiscUtils.h>
#include <ZPreferences.h>
#include <ZRegularDesktop.h>
#include <ZStringUtils.h>
#if RAVEN_OPERATOR_NEW
#include <ZBestFitAllocator.h>
#include <ZMemoryHeap.h>
#include <ZNewAndDelete.h>
#include <ZSimpleAllocator.h>
#endif
#include "App.h"
// ===================================================================================
// class TBootStrap
// ===================================================================================
//---------------------------------------------------------------
//
// TBootStrap::DoEarlyInit
//
// This is called after the toolbox is initialized, but before
// static objects are constructed. You shouldn't have to do
// anything besides creating the object heap here. (Use OnBoot
// if you need to initialize other things).
//
//---------------------------------------------------------------
void TBootStrap::DoEarlyInit()
{
const long kInitialObjectHeapSize = 500*1024L; // ・・・ハadjust these numbers
const long kObjectHeapIncrementSize = 32*1024L;
const short kNumMasterPtrBlocks = 10;
for (short i = 1; i <= kNumMasterPtrBlocks; i++)
MoreMasters();
#if RAVEN_OPERATOR_NEW // on by default
ASSERT(gObjectHeap == nil);
TAllocator* alloc = new TSimpleAllocator(kInitialObjectHeapSize, kObjectHeapIncrementSize);
gObjectHeap = new TMemoryHeap(alloc);
#else
_prealloc_newpool(kInitialObjectHeapSize);
_set_newpoolsize(kObjectHeapIncrementSize);
_set_newnonptrmax(kObjectHeapIncrementSize/4);
#endif
}
#pragma mark -
// ===================================================================================
// class CMyBooter
// TAppBootStrap initializes some of the core Raven classes and checks to make
// sure the machine is capable of running your app.
// ===================================================================================
class CMyBooter : public TAppBootStrap {
typedef TAppBootStrap Inherited;
//-----------------------------------
// Initialization/Destruction
//
public:
virtual ~CMyBooter();
CMyBooter();
//-----------------------------------
// Inherited API
//
protected:
virtual void OnSystemNeeds(list<string, allocator<string> >& needs);
virtual void OnBoot();
};
//---------------------------------------------------------------
//
// CMyBooter::~CMyBooter
//
//---------------------------------------------------------------
CMyBooter::~CMyBooter()
{
Terminate3D();
}
//---------------------------------------------------------------
//
// CMyBooter::CMyBooter
//
//---------------------------------------------------------------
CMyBooter::CMyBooter()
{
mIdealDisplayMode = SDisplayMode(640, 480, 32); // QuickDraw 3D works best in direct color
#if !DEBUG
mCanChangeDevice = true;
#endif
}
//---------------------------------------------------------------
//
// CMyBooter::OnSystemNeeds
//
// If your app requires things that aren't on every machine (eg
// QuickDraw 3D, the Drag Manager, etc) add a test here. TBootStrap
// will popup a dialog listing all of the items that are missing
// from the user's machine.
//
//---------------------------------------------------------------
void CMyBooter::OnSystemNeeds(list<string, allocator<string> >& needs)
{
Inherited::OnSystemNeeds(needs);
if (!UGestalt::hasQuickDraw3D)
needs.push_back("QuickDraw 3D");
}
//---------------------------------------------------------------
//
// CMyBooter::OnBoot
//
// This is the best place to initialize stuff.
//
//---------------------------------------------------------------
void CMyBooter::OnBoot()
{
Inherited::OnBoot();
// Aplications often have just a few block sizes that account
// for the bulk of their operator new allocations. You can
// speed up operator new by calling AddAllocator for these
// common sizes. (You can find the most used block sizes by
// using the "Dump Object Heap" command in the Debug menu).
gObjectHeap->AddAllocator(20, 400);
TFloatingDesktop::Init();
if (!Init3D()) {
ReportError(LoadAppString("Couldn't startup!"), LoadAppString("Failed to initialize QuickDraw 3D."));
ExitToShell();
}
UPreferences::Init("BoxPaint Prefs", 'SKEL');
}
#pragma mark -
//---------------------------------------------------------------
//
// Main
//
//---------------------------------------------------------------
void main()
{
CMyBooter booter;
booter.Boot();
{
CApplication theApp;
theApp.Run();
}
}